#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
int N;
int a[maxn], s[maxn];
int lis[maxn], idx;
int main() {
  cin >> N;
  memset(lis, 0x3f, sizeof lis);
  for (int i = 1; i <= N; ++i) cin >> a[i];
  for (int i = 1; i <= N; ++i) {
    int pos = lower_bound(lis, lis + idx, a[i]) - lis;
    if (lis[pos] > a[i]) lis[pos] = a[i];
    if (pos == idx) {
      idx++;
    }
  }
  cout << idx << endl;
}
